﻿function TodoList() {
  var i = 1;

  // public
  this.todos = new Array();

  // private
  function Item(comment) {
    this.id = i++;
    this.done = false;
    this.comment = comment;
    // why?
    this.flagClass = '';
    this.checkboxAttribute = '';
  }

  // public
  this.add = function (comment) {
    this.todos.push(new Item(comment));
  };

  // public
  this.toggleFlag = function (id) {
    for (var j = 0; j < this.todos.length; j++) {
      if (this.todos[j].id == id) {
        this.todos[j].done ? this.todos[j].flagClass = '' : this.todos[j].flagClass = 'flagClass';
        this.todos[j].done ? this.todos[j].checkboxAttribute = '' : this.todos[j].checkboxAttribute = 'checked="checked"';
        this.todos[j].done ? this.todos[j].done = false : this.todos[j].done = true;
      }
    }
  };

  // public
  this.remove = function (id) {
    for (var j = 0; j < this.todos.length; j++) {
      if (this.todos[j].id == id)
        this.todos.splice(j, 1);
    }
  };
}
